# @Author: Eric Ito
# @Date: 1/28/2009
# @Name: Project Euler Problem 22


"""
Find name score of all names in names.txt and sum them
"""

import os
from util import LTRMAP

def load(txtfile):
	f = open(txtfile,'r')
	NAMES = []
	for line in f.readlines():
		NAMES = line.split(',')
	f.close()
	return NAMES

def getNameScore(name,rank):
	multiplier = 0
	for ltr in name:
		multiplier += LTRMAP[ltr]
	return multiplier*rank

def main():
	NAME_LIST = load("names.txt")
	NAME_LIST.sort()
	i=1
	NAME_DICT = {}
	totalNameScore = 0
	for name in NAME_LIST:
		newname = str(name)[1:-1]
		namescore = getNameScore(newname,i)
		NAME_DICT[i] = (newname,namescore)
		totalNameScore += namescore
		i +=1
	print NAME_DICT
	print totalNameScore
		
	
	
if __name__ == "__main__":
	main()